package com.dhnsoft.shortLink.admin.controller;

import com.dhnsoft.shortLink.admin.common.convention.result.Result;
import com.dhnsoft.shortLink.admin.common.convention.result.Results;
import com.dhnsoft.shortLink.admin.dto.req.ShortLinkGroupSaveReqDTO;
import com.dhnsoft.shortLink.admin.dto.req.ShortLinkGroupSortReqDTO;
import com.dhnsoft.shortLink.admin.dto.req.ShortLinkGroupUpdateReqDTO;
import com.dhnsoft.shortLink.admin.dto.resp.ShortLinkGroupRespDTO;
import com.dhnsoft.shortLink.admin.service.GroupService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: GroupController
 * Package: com.dhnsoft.shortLink.admin.controller
 * Description:
 *
 * @Author dhn
 * @Create 2024/3/19 17:01
 * @Version 1.0
 */
@RestController
@RequiredArgsConstructor
public class GroupController {

    private final GroupService groupService;

    @PostMapping("/api/short-link/admin/v1/group")
    public Result<Void> save(@RequestBody ShortLinkGroupSaveReqDTO requestParam){
        groupService.saveGroup(requestParam.getName());
        return Results.success();
    }


    @GetMapping("/api/short-link/admin/v1/group")
    public Result<List<ShortLinkGroupRespDTO>> listGroup(){
        return Results.success(groupService.listGroup());
    }


    @PutMapping("/api/short-link/admin/v1/group")
    public Result<Void> updateGroup(@RequestBody ShortLinkGroupUpdateReqDTO requestParam){
        groupService.updateGroup(requestParam);
        return Results.success();
    }

    @DeleteMapping("/api/short-link/admin/v1/group")
    public Result<Void> deleteGroup(@RequestParam String gid){
        groupService.deleteGroup(gid);
        return Results.success();
    }


    @PostMapping("/api/short-link/admin/v1/group/sort")
    public Result<Void> sortGroup(@RequestBody List<ShortLinkGroupSortReqDTO> requestParam){
        groupService.sortGroup(requestParam);
        return Results.success();
    }


}
